package com.eascs.o2o.reloan.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.o2o.common.vo.ModelResult;
import com.eascs.o2o.recruit.entity.ApplyForInfoVO;
import com.eascs.o2o.recruit.entity.OfficeForInfoVO;
import com.eascs.o2o.recruit.service.ApplyForInfoService;
import com.eascs.o2o.reloan.service.ReLoanApplyService;

@Service
public class ReLoanApplyServiceImpl implements ReLoanApplyService {
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private ApplyForInfoService applyForInfoService;
	
	@Override
	@Transactional(transactionManager = "transactionManager")
	public ModelResult<Boolean> applyLoan(ApplyForInfoVO applyInfo, OfficeForInfoVO officeInfo) {
		ModelResult<Boolean> modelResult=new ModelResult<>();
		try {
			applyForInfoService.saveApplyForInfo(applyInfo);
		} catch (Exception e) {
			logger.info("ReLoanApplyServiceImpl.applyLoan.error.saveApplyForInfo,exception:{}");
			//return modelResult.withError("applyLoan.error.insertApplyLoanEntity", "申请贷款表插入失败");
			throw new RuntimeException("申请续贷表插入失败"); // 回滚事物
		}
		officeInfo.setApplyerId(applyInfo.getId());
		try {
			applyForInfoService.saveOfficeForInfo(officeInfo);
		} catch (Exception e) {
			logger.info("ReLoanApplyServiceImpl.applyLoan.error.saveOfficeForInfo,exception:{}");
			//return modelResult.withError("applyLoan.error.insertApplyStoreEntity", "申请贷款门店信息表插入失败");
			throw new RuntimeException("申请续贷门店信息表插入失败"); // 回滚事物
		}
		modelResult.withModel(true);
		return modelResult;
	}

}
